package com.hualan.servlet;

import com.alibaba.fastjson.JSON;
import com.hualan.bean.AssociateShop;
import com.hualan.dao.CommunityDao;
import com.hualan.dao.impl.CommunityDaoImpl;
import com.hualan.utils.C3P0Util;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/communitySelectAssociateShop")
public class CommunitySelectAssociateShop extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String pageString = req.getParameter("page");
        int page = pageString == null ? 1 : Integer.parseInt(pageString);
        String sizeString = req.getParameter("size");
        int size = sizeString == null ? 10 : Integer.parseInt(sizeString);
        int id = Integer.parseInt(req.getParameter("community_id"));
        CommunityDao communityDao = new CommunityDaoImpl();
        List<AssociateShop> list = communityDao.selectAssociateShop(page,size,id);
        System.out.println(list);
        Map<String,Object> map = new HashMap<>();
        map.put("list",list);
        if (list != null){
            map.put("code",200);
            map.put("message","请求成功");
        }else {
            map.put("code",300);
            map.put("message","请求失败");
        }
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        resp.getWriter().write(JSON.toJSONString(map));
    }
}
